<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body { background:#fff; }
			.my_bag .top{ padding: 15px 15px 0;}
			.my_bag .top li{ border-radius: 6px 6px 0 0; padding: 20px 10px; background: linear-gradient(to right, #e2af31, #f2ce7e); box-shadow: 0 0 10px rgba(226,175,51,0.3); color: #fff; overflow: hidden;}
			.my_bag .top p{ font-size: 12px; opacity: 0.9; line-height: 20px;}
			.my_bag .top b{ display:block; font-size: 30px; font-weight: 500; line-height: 30px; padding-top: 7px;}
			.my_bag .list{ background-color:#fff;box-shadow: 0 -3px 5px rgba(226,175,51,0.33);}
			.my_bag .list li{ position: relative; padding: 1px 15px;}
			.my_bag .list li::after{position: absolute; content: ""; left: 45px; right: 0; bottom: 0; border-bottom: 1px #d4d4d4 solid; transform: scaleY(0.5);}
			.my_bag .list .m_cell_hd img{ width: 25px; margin-right: 10px;}
			.my_bag .list h4{ display:block; font-size: 14px; font-weight: 500; color: #333; line-height: 50px;}
			.my_bag .list .m_cell_ft img{ width: 6px;}

		</style>
	</head>
	<body>
		<div class="my_bag">
			<ul class="top">
				<li>
					<p>我的余额</p>
					<b id="mycredit">￥-</b>
				</li>
			</ul>
			<ul class="list">
				<li tapmode="lipress" onclick="openNavWin('#ddd','tixian_win','tixian_frm.html','提现申请',false,false,true,[],{});">
					<div class="m_cell_hd"><img src="../../image/img_17.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>提现</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li tapmode="lipress" onclick="openNavWin('#ddd','creditlog_win','creditlog_frm.html','余额记录',false,false,true,[],{});">
					<div class="m_cell_hd"><img src="../../image/img_18.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>余额记录</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
			</ul>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript">
		apiready = function() {
			api.parseTapmode();
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					$api.text($api.byId('mycredit'),"￥"+userinfo.credit);
					getJsonFromAPI();
				}
			});
			api.addEventListener({
				name : 'updatecredit'
			}, function(ret, err) {
				
				getJsonFromAPI();
			});
			api.addEventListener({
                name: 'navitembtn'
            }, function(ret, err) {
                if (ret.type == 'left') {
					api.closeWin({
					});
                }
            });
			api.addEventListener({
				name : 'reloadpage'
			}, function(ret, err) {
				getJsonFromAPI();				
			});
		}
		function getJsonFromAPI() {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/credit',
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						
						if (ret) {
							$api.text($api.byId('mycredit'),ret.credit);
							userinfo.credit = ret.credit;
							api.setPrefs({
								key: 'user_info',
								value: userinfo
							}, function(ret, err) {
								if(ret)
								{
									
								}
							});
							
							
							
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								toast('网络异常');
								console.log(JSON.stringify(err));
							}
						}
					});
				}
			});
		}
	</script>
</html>
